﻿using System.Collections;
using System.Collections.Generic;
using Entitas;
using UnityEngine;


namespace Internal
{
    public class ChangeRotationSystem : ReactiveSystem<GameEntity>
    {

        public ChangeRotationSystem(Contexts contexts) : base(contexts.game)
        {

        }

        protected override void Execute(List<GameEntity> entities)
        {
            foreach (GameEntity entity in entities)
            {
                Transform view = entity.internalView.viewTrans;
                float angle = entity.internalDirection.dir;
                view.rotation = Quaternion.AngleAxis(angle-90,Vector3.forward);
              
            }
        }

        protected override bool Filter(GameEntity entity)
        {
            return entity.hasInternalDirection
                && entity.hasInternalMove
                && entity.hasInternalView
                && entity.isInternalMoveComplete;
        }

        protected override ICollector<GameEntity> GetTrigger(IContext<GameEntity> context)
        {
            return context.CreateCollector(GameMatcher.InternalDirection);
        }
    }
}



